

#include<iostream>
#include<vector>
#include<Bitset>   
using namespace std;
namespace bit {
	template <size_t T>
	class bitmap
	{
	public:
		bitmap()
			:_bs(ceil(T/32.0))
		{}
		void set(int n)
		{
			int i = n / 32;//找到所在整形的下标
			int j = n % 32;//找到所在整形中对应的比特位
			_bs[i] |= 1 << j;
		}

		void reset(int n)
		{
			int i = n / 32;//找到所在整形的下标
			int j = n % 32;//找到所在整形中对应的比特位
			_bs[i] &= ~(1 << j);  
		}


		bool test(int n)
		{
			int i = n / 32;//找到所在整形的下标
			int j = n % 32;//找到所在整形中对应的比特位
			return _bs[i] & (1 << j); 
		}

		private:
			vector<int>_bs;  
	};

	template <size_t T>
	class twoset
	{
	public:
		twoset() = default;
		void set(size_t n)
		{
			//00->01
			if (!bs1.test(n) && !bs2.test(n))
			{
				bs2.set(n);
			}
			else if (!bs1.test(n) && bs2.test(n))//01->10
			{
				bs1.set(n);
				bs2.reset(n);
			}
			else//10->11
			{
				bs2.set(n);
			}
		}

		int get_count(int n)
		{
			return bs1.test(n)*2 + bs2.test(n);
		}


	private:
		bitmap<T>bs1;    
		bitmap<T>bs2;     
	};

}



int main()
{
	/*bit::bitmap<40>bitmap;
	bool ret = 0; size_t count = 0; 
	for (int i = 0; i <= 25; i++)
	{
		bitmap.set(i);
		ret = bitmap.test(i);
		bitmap.reset(i);
		cout << bitmap.test(i) << endl; 
		if (ret) count++;
	}
	cout << "all is " << count << endl;
	bitset<100>bs;*/
	bit::twoset<100>bs; 
	vector<int>arr{ 1,4,5,6,3,2,14,8,5,4,7,8,5,1,2,4};
	for (auto x : arr)
	{
		bs.set(x);
	}
	for (int i=0;i<15;i++)
	{
		size_t x = i;
		cout << x << "->";
		if (bs.get_count(x) >= 2)
		{
			cout << "2或以上" << endl;
		}
		else
			cout << bs.get_count(x) << endl;
	}

	return 0;
}

